package com.yanjin.dao;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jdbc.tool.DBLianjie;

public class AddDao extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String biaoqian=request.getParameter("hname");
		String userid=request.getParameter("userId");
		String username=request.getParameter("username");
		String passWord=request.getParameter("userpass");
		String sex=request.getParameter("sex");
		
		String birthyear =request.getParameter("birthyear");
        String birthmonth =request.getParameter("birthmonth");
        String birthday =request.getParameter("birthday");
		
  	  String userCarid=request.getParameter("userCarid");
	  String email=request.getParameter("email");
	  String pone=request.getParameter("pone");
	  String addres=request.getParameter("addres");
	  String jibie=request.getParameter("jibie");
	  String beizhu=request.getParameter("beizhu");
	  
	  String birthDay= birthyear+"-"+birthmonth+"-"+birthday;
      SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
      		
		Connection conn=null;
		Statement stm=null;
		 String sql="insert into emai_user(E_USER_ID,E_USER_NAME,E_PASSWORD,E_SEX,E_BRITHDAY,E_IDENTITY_CODE,E_EMIAL,E_MOBILE,E_ADDRESS,E_STATUS,E_LJ) values " +
	  		"('"+userid+"','"+username+"','"+passWord+"','"+sex+"',to_date('"+birthDay+"','yyyy-MM-dd'),'"+userCarid+"','"+email+"','"+pone+"','"+addres+"','"+jibie+"','"+beizhu+"')";
	     conn=DBLianjie.getconn();
       try {
		stm=conn.createStatement();
		boolean x=stm.execute(sql);
		if(!x){
			if("add".equals(biaoqian)){
			response.sendRedirect("SelectAllUser.jsp");
			}else if("zhuce".equals(biaoqian)){
			response.sendRedirect("Login.html");
			}
		}else{
		}
	} catch (SQLException e) {
		e.printStackTrace();
	}
		
	}

}
